﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Data;
using DAL;

public partial class ProductCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           
         }

        LoadData();
    }
    ProductBLL dataProduct = new ProductBLL();
    void LoadData()
    {
        int Cate = Convert.ToInt32(Request.QueryString["Id"]);
        int Sort = Convert.ToInt32(dropSort.SelectedValue);
        if (Cate == 1)
        {
            //New
            int top = 2000000;
            var listProduct = dataProduct.GetByTopNew(top, true, true);
            if (Sort == 1)
                listProduct = listProduct.OrderBy(p => p.Cost).ToList();
            else listProduct = listProduct.OrderByDescending(p => p.Cost).ToList();
            DataTable tb2 = Myfunction.ConvertToDataTable(listProduct);
            clPages.MaxPages = 100000;
            clPages.PageSize = 20;
            clPages.DataSource = tb2.DefaultView;
            clPages.BindToControl = rptProductFilter;

            rptProductFilter.DataSource = clPages.DataSourcePaged;
            rptProductFilter.DataBind();
        }
        if (Cate == 2)
        {
            int top = 2000000;
            var listProduct = dataProduct.GetByTopBuy(top, true, true);
            if (Sort == 1)
                listProduct = listProduct.OrderBy(p => p.Cost).ToList();
            else listProduct = listProduct.OrderByDescending(p => p.Cost).ToList();
            DataTable tb2 = Myfunction.ConvertToDataTable(listProduct);
            clPages.MaxPages = 100000;
            clPages.PageSize = 20;
            clPages.DataSource = tb2.DefaultView;
            clPages.BindToControl = rptProductFilter;

            rptProductFilter.DataSource = clPages.DataSourcePaged;
            rptProductFilter.DataBind();
        }
    }

    protected void rptProductFilter_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        SizeBLL dataSize = new SizeBLL();
        LabelBLL dataLabel = new LabelBLL();
        Label lbProductID = (Label)e.Item.FindControl("lbId");
        Label lbLabelId = (Label)e.Item.FindControl("lbLabelId");
        string productId = lbProductID.Text.ToString();

        var listSize = dataSize.GetByProductId(productId);
        DataTable tbSize = Myfunction.ConvertToDataTable(listSize);

        Repeater rptSize = (Repeater)e.Item.FindControl("rptSize");
        rptSize.DataSource = tbSize;
        rptSize.DataBind();

        //List<LabelSP> listLabel = new List<LabelSP>();
        //LabelSP lp = dataLabel.GetById(int.Parse(lbLabelId.Text));
        //listLabel.Add(lp);
        //DataTable tbLabel = Myfunction.ConvertToDataTable(listLabel);
        //Repeater rptLabel = (Repeater)e.Item.FindControl("rptLabel");
        //rptLabel.DataSource = tbLabel;
        //rptLabel.DataBind();

    }
}